package com.flyoil.petromp.ui.activity.activity_me;

import android.app.ActionBar;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cnpc.fyimageloader.glide.GlideHelper;
import com.flyoil.petromp.R;
import com.flyoil.petromp.base.BaseActivity;
import com.flyoil.petromp.utils.MoccaPreferences;

public class SeeSignatureActivity extends BaseActivity {
    private ImageView img_siganture;
    private TextView tv_rewrite;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_see_signature;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setTextTitleName("个人签名");

        setBackOnclickListner(mContext);
//        setTextRightName("使用说明");
        img_siganture = $(R.id.img_see_signature_icon);
        tv_rewrite = $(R.id.tv_see_signature_rewrite);

    }

    @Override
    protected void onResume() {
        super.onResume();
        GlideHelper.showImage(mContext, MoccaPreferences.user_signature.get(), img_siganture);
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        setTextRightOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                show_signature_help_dialog(img_siganture);
            }
        });
        tv_rewrite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext, SetSignatureActivity.class));
            }
        });
    }

    /**
     * 显示设置签名的用法帮助的弹框
     */
    public void show_signature_help_dialog(View view) {
        View v1 = LayoutInflater.from(mContext).inflate(R.layout.popup_siganture_help, null);// 创建view
        final PopupWindow popupWindow = new PopupWindow(v1, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, true);// 实例化popupwindow的方法
        popupWindow.setBackgroundDrawable(new ColorDrawable());
        // 这个方法是为了当点击除了popupwindow的其他区域可以关闭popupwindow的方法
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        View view_top = v1.findViewById(R.id.view_popup_signature_top);
        view_top.setVisibility(View.GONE);
        View view_cancle = v1.findViewById(R.id.view_popup_signature_cancle);
        View view_confirm = v1.findViewById(R.id.view_popup_signature_confirm);
        view_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
        view_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
    }
}
